<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>

<body>
    <div id="app">
        <count @click="changeNum"></count>
        <h3>当前的值为:{{num}}</h3>
    </div>

    <template id="cpn">
        <div>
            <button @click="increase">+</button>
            <button @click="decrease">-</button>
        </div>
    </template>
</body>
<script>
    Vue.component('count', {
        template: '#cpn',
        data(){
            return{
                count:1
            }
        },
        methods:{
            increase(){
                this.count++;
                this.$emit("click",this.count)
            },
            decrease(){
                this.count--;
                this.$emit("click",this.count)
            }
        }
    })

    const vm = new Vue({
        el: '#app',
        data: {
            num:1
        },
        methods: {
            changeNum(e){
                this.num=e;
            }
        }
    })
</script>

</html>